#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
string s;
int ca, cb, cab, cba;
bool solve() {
  cin >> s >> ca >> cb >> cab >> cba;
  n = s.size();

  vector<int> ab, ba;
  int x = 0, y = 0, z = 0;
  int l = 0;
  while (l < n) {
    int h = l + 1;
    while (h < n && s[h] != s[h - 1]) h++;
    int len = h - l;
    if (len & 1) {
      if (s[l] == 'A') {
        ca--;
        if (ca < 0) return false;
      } else {
        cb--;
        if (cb < 0) return false;
      }
      z += len / 2;
    } else {
      if (s[l] == 'A')
        x += len / 2, ab.push_back(len / 2);
      else {
        y += len / 2, ba.push_back(len / 2);
      }
    }
    l = h;
  }
  if (min(ca, cb) + cab + cba < x + y + z) return false;
  sort(ab.begin(), ab.end(), greater<int>());
  sort(ba.begin(), ba.end(), greater<int>());
  while (ab.size() && cab) {
    int now = min(cab, ab.back());
    x -= now;
    cab -= now;
    ab.back() -= now;
    if (ab.back() == 0) ab.pop_back();
  }
  while (ba.size() && cba) {
    int now = min(cba, ba.back());
    y -= now;
    cba -= now;
    ba.back() -= now;
    if (ba.back() == 0) ba.pop_back();
  }
  int need = ab.size() + ba.size();
  return need <= min(ca, cb);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) cout << (solve() ? "YES\n" : "NO\n");
  return 0;
}